package com.tywj.panda.customer.common.http

import org.json.JSONObject

/**
 * @desc 网络请求回调，只返回状态和提示信息，不返回数据
 * @author June Yang
 * @date 2020/5/8
 */
abstract class PDStringCallback(isHandleErrorSelf: Boolean = false) :
    PDBaseCallback(isHandleErrorSelf) {

    override fun onSuccess(data: String) {
        val responseData = JSONObject(data)
        val code = responseData.getInt("code")
        val message = responseData.getString("msg")

        if (code == 0) {
            success(message)
        } else {
            handleAsyncRequestError(code, message)
        }
    }

    abstract fun success(message: String)
}